import { _decorator, Button, Label, size, Sprite, UITransform } from 'cc';
import { $planet_BasePop_poof$ } from '../../../frame/component/ui.pop';
import $planet_GameAssets_poof$ from '../manager/game-assets';
import type { $planet_Pop_poof$ } from '../ui/pop';
const { ccclass, property } = _decorator;

@ccclass('$planet_ELSB_poof$')
export class $planet_Elsb_poof$ extends $planet_BasePop_poof$<typeof $planet_Pop_poof$, null> {
	protected $planet_default_return_poof$: null;

	protected $planet_initAfterOnLoad_poof$(): void {
		this.$planet_renderLocalUI_poof$();
	}

	public $planet_onShow_poof$(){
		this.$planet___btn_map___poof$.get('convert').interactable = false;
		$planet_BasePop_poof$.$planet_jelly_enter_poof$(this.node)
		.then(()=> this.$planet___btn_map___poof$.get('convert').interactable = true );
	}

	protected $planet__click_event__poof$: { [name: string]: (this: $planet_Elsb_poof$, button: Button) => void; } = {
		convert(btn){
			btn.interactable = false;
			$planet_BasePop_poof$.$planet_jelly_leave_poof$(this.node).then(()=>{
				this.$planet_close_poof$(null);
				btn.interactable = true;
			});
		}
	}

	private $planet_renderLocalUI_poof$(){
		let ui_title = this.node.getChildByName('title-word').getComponent(UITransform);
		let ui_convert = this.$planet___btn_map___poof$.get('convert').getComponent(UITransform);

		(<const>[
			[ui_title, size(this.node.getComponent(UITransform).width, ui_title.height), $planet_GameAssets_poof$.$planet_getLangTexture_poof$(10)],
			[ui_convert.node.getChildByName('word').getComponent(UITransform), ui_convert.contentSize, $planet_GameAssets_poof$.$planet_getLangTexture_poof$(3)],
		]).forEach(([ui, size, sframe])=>{
			let [R, r] = [size, sframe.originalSize].map(s=>s.width/s.height);
			if(r > R){
				let ratio = abd.$planet_size_poof$.$planet_innerRatio_poof$(sframe.originalSize, size) * 0.9;
				ui.getComponent(Sprite).spriteFrame = sframe;
				ui.setContentSize(sframe.originalSize.width * ratio, sframe.originalSize.height * ratio);
			}else abd.$planet_cc_poof$.$planet_skinPeeler_poof$(ui.node, sframe, true);
		});

		this.node.getChildByName('lbl-desc').getComponent(Label).string = $planet_GameAssets_poof$.$planet_getLangText_poof$(0);
	}
}

